<!DOCTYPE html>
<html>
  <head>
    <title>Pyxel Web Launcher</title>
    <script src="https://cdn.jsdelivr.net/gh/kitao/pyxel/wasm/pyxel.js"></script>
  </head>
  <body class="pyxel-scheme">
    <script>
      const queries = new URL(document.location).searchParams;
      let command, paths, ext;

      if (queries.get("run")) {
        command = "run";
        paths = queries.get("run").split(".");
        ext = ".py";
      } else if (queries.get("play")) {
        command = "play";
        paths = queries.get("play").split(".");
        ext = ".pyxapp";
      } else if (queries.get("edit")) {
        command = "edit";
        paths = queries.get("edit").split(".");
        ext = ".pyxres";
      } else {
        location.replace("url-builder.html");
      }

      if (command) {
        launchPyxel({
          root: "https://cdn.jsdelivr.net/gh/" + paths.slice(0, 2).join("/"),
          command: command,
          name: paths.slice(2).join("/") + ext,
          packages: queries.get("packages"),
          gamepad: queries.get("gamepad"),
          editor: queries.get("editor"),
        });
      }
    </script>
  </body>
</html>
